With custom apps you can store JSON Data in the JSON Database, you can also managing the settings of the database like Website access or title.

This can be done through the admin portal or can be set from a custom app.

Getting Started

To get started, navigate to the Data / JSON Data section of your admin site. Create a new JSON database with the large green button at top left. Choose a simple name (note the naming restrictions) and a title for your database.

Your new database appears as a row in the table. The blue button to the right of the row allows you to either manage or delete your database. Click the manage button.

You now see four tabs, Details, Notes, Records and Query.

Details

This page allows you to set several options:

  • Name : You can change the name of the database that you chose when you created it. Note that the same restrictions on valid name characters still apply.
  • Title : You can change the title of the database that you chose when you created it.
  • Template : TODO
  • Website : Choose a website that has access to this JSON database.
  • Allow access from any website : Allow any website on this account access to this JSON database. This option overrides the previous one.
  • Allow REST operations : Allow reading from and writing to the JSON database directly via JSON data posted to the database URL.
  • Readonly : your database can be read from any website with access, but can only be written to from the admin interface.

Notes

Any text can be added here, but it has no effect on the operation of the database.

Records

You can add, import and delete records from your JSON database in this tab.

Add record

Click the Add record button and get a dialog to add a new record.

Every record must have a simple name that is a valid JSON string, and a document type. The body of the record must be valid JSON.

Delete record

Select one or more records by checkbox and click the delete button.

Import records

Click the Import CSV button for a dialog to upload a CSV file.

There are few restrictions on the format and capabilities of the CSV import:

  • The first column in the CSV file must be a unique string that will become the simple name for the record.
  • The second column in the CSV file must be a document type for the record.
  • The first row in the CSV file defines the field names for all subsequent lines.
  • The first and second fields in the first line must be "name" and "docType" respectively.
  • Escape double quotes ( " ) with a second double quote ( "" )
  • The backslash or reverse solidus is ignored.
  • Records with the same name will be updated with the most recent entry.
  • All data are treated as strings.

Query

Arbitrary JSON queries can be executed in this tab for development and testing purposes.

Using the API

Doing with a the custom app that will be using the database makes it simply to manage the database for the app, and maybe you want the app to control access to the database.

On the server side JavaScript you can access the database when a user calls a GET, POST or DELETE method by using the "page" parameter passed to the method. From this you can call page.find('/jsondb/{you database name}').

Once you have the JSON Database resource you can call the following functions to get or set settings:

  • name
  • title
  • template
  • website
  • allowRest
  • allowAccess
  • readOnly

For example to set the database to allow access you would do something similar to this:

      var jsonDB = page.find('/jsondb/myDB');
      transactionManager.begin();
      jsonDB.setAllowAccess(allowAccess);
      transactionManager.commit();
    

To see if the database has read only right you would have the following code:

      var jsonDB = page.find('/jsondb/myDB');
      var readOnly = jsonDB.readOnly;
    

Or to get the title of the database and add some text and save it again:

      var jsonDB = page.find('/jsondb/myDB');
      var dbTitle = jsonDB.title;
      transactionManager.begin();
      jsonDB.setTitle(dbTitle + "_2");
      transactionManager.commit();
    

Ask a question, or offer an answer